#pragma once

#include <string>
#include <map>
#include <memory>
#include <mutex>
#include <chrono>

class SessionManager {
public:
    static SessionManager& getInstance();
    
    // 创建新session
    std::string createSession();
    
    // 获取session数据
    std::string getSessionData(const std::string& session_id, const std::string& key);
    
    // 设置session数据
    void setSessionData(const std::string& session_id, 
                       const std::string& key, 
                       const std::string& value);
    
    // 删除session
    void removeSession(const std::string& session_id);
    
    // 清理过期session
    void cleanupExpiredSessions();
    
private:
    SessionManager() = default;
    SessionManager(const SessionManager&) = delete;
    SessionManager& operator=(const SessionManager&) = delete;
    
    struct SessionData {
        std::map<std::string, std::string> data;
        std::chrono::system_clock::time_point expiry;
    };
    
    std::map<std::string, SessionData> sessions_;
    std::mutex mutex_;
    const std::chrono::minutes session_timeout_{30};
    
    std::string generateSessionId();
}; 